<template>
  <div>
    <a-row class="price-content">
      <a-col>
        <div class="top-btns">
          <!-- <a-button type="primary" @click="openDialog()"><a-icon type="select" />选择服务商</a-button> -->
          <a-button type="primary" @click="save()"><a-icon type="save" />保存</a-button>
          <a-button type="primary" @click="goback()"><a-icon type="rollback" />返回</a-button>
        </div>
      </a-col>
    </a-row>
    <a-form :form="form" class="form-wrap basic-form-pop">
      <a-form-item label="服务商id：">
        <a-input v-model="params.id" disabled/>
      </a-form-item>
      <a-form-item label="服务商账号：">
        <a-input v-model="params.partner_no" disabled/>
      </a-form-item>
      <a-form-item label="服务商姓名：">
        <a-input v-model="params.partner_name" disabled/>
      </a-form-item>
      <a-form-item label="服务商手机号：">
        <a-input v-model="params.phone" disabled/>
      </a-form-item>
      <a-form-item label="分润状态：">
        <a-input v-if="params.is_commission" value="开启" disabled/>
        <a-input v-else value="关闭" disabled/>
      </a-form-item>
      <a-form-item label="账号状态：">
        <a-input v-if="params.is_enable" value="开启" disabled/>
        <a-input v-else value="关闭" disabled/>
      </a-form-item>
      <a-form-item label="类型：">
        <a-input v-if="params.type===1" value="个人" disabled/>
        <a-input v-if="params.type===2" value="企业" disabled/>
      </a-form-item>
      <a-form-item label="省份：">
        <a-input v-model="params.province_name" disabled/>
      </a-form-item>
      <a-form-item label="城市：">
        <a-input v-model="params.city_name" disabled/>
      </a-form-item>
      <a-form-item label="区/县：">
        <a-input v-model="params.district_name" disabled/>
      </a-form-item>
      <a-form-item
        label="*充值金额："
        class="number-style"
      >
        <a-input-number
          :min="0"
          :max="params.allParticipation"
          v-model.trim="params.participation"
          @change="change"
        />
      </a-form-item>
      <a-form-item label="待充值金额：">
        <a-input v-if="params.allParticipation" v-model="stayRecharge" disabled/>
      </a-form-item>
      <a-form-item label="备注：">
        <a-textarea v-model.trim="remark" placeholder :rows="4" maxlength="199" />
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
let temporaryData = null
const rowSelection = {
  type: 'radio',
  onChange(selectedRowKeys, selectedRows) {
    temporaryData = { ...selectedRows[0] }
  }
}
import { feeRecharge, getPartner, part } from '../../../store/providerApi'
// import { debuglog } from 'util'
export default {
  props: {
    uuid: {
      type: String,
      required: true
    }
  },
  computed: {
    stayRecharge() {
      if (this.params.allParticipation && this.params.participation) {
        return this.params.allParticipation - this.params.participation
      } else if (!this.params.participation) {
        return this.params.allParticipation
      }
    }
  },
  data() {
    return {
      show: false,
      form: this.$form.createForm(this),
      name: '',
      remark: '',
      params: {},
      loading: false,
      SPData: [],
      SPList: [
        {
          title: 'id',
          dataIndex: 'id'
        },
        {
          title: '服务商账号',
          dataIndex: 'account'
        },
        {
          title: '服务商名称',
          dataIndex: 'name'
        },
        {
          title: '手机号码',
          dataIndex: 'phone'
        },
        {
          title: '所在区域',
          dataIndex: 'address'
        }
      ],
      rowSelection
    }
  },
  beforeMount() {
    this.feeRecharge()
  },
  methods: {
    // 充值金额
    change(value) {
      if (value > this.params.allParticipation) {
        this.params.participation = this.params.allParticipation
      }
    },
    // 打开服务商弹窗
    // openDialog() {
    //   this.show = true
    //   this.nameDisabled = true
    //   this.name = ''
    //   this.getPartner()
    // },
    // 关闭服务商
    // closeDialog() {
    //   this.show = false
    // },
    // 查询服务商
    // getMember() {
    //   this.getPartner()
    // },
    // 选择服务商
    // choiceSP() {
    //   const { id } = temporaryData
    //   this.feeRecharge(id)
    //   this.show = false
    // },
    // 获取服务商
    // getPartner() {
    //   let params = {
    //     page: 1,
    //     num: 10,
    //     name: this.name
    //   }
    //   this.loading = true
    //   getPartner(params).then(res => {
    //     if (!res.error) {
    //       this.loading = false
    //       this.SPData = res.data.list
    //     }
    //   })
    // },
    // 获取服务商详情
    feeRecharge() {
      // 获取服务商信息
      feeRecharge({
        id: this.uuid
      }).then(res => {
        if (!res.error) {
          res.data.allParticipation = res.data.to_participation
          this.params = res.data
          this.params.participation = 0
          console.log(this.params)
        }
      })
    },
    // 保存服务商
    save() {
      const { uuid: id, participation: amount } = this.params
      const remark = this.remark || undefined
      if (amount < 0.01) {
        this.$message.error('充值金额最少0.01元')
        return
      }
      let params = {
        id,
        amount,
        remark
      }
      // 手动充值
      part(params).then(res => {
        if (!res.error) {
          this.$message.success(res.data.message)
          this.$emit('closePop')
        }
      })
    },
    goback () {
      this.$emit('closePop')
    }
  }
}
</script>
